--[[				lolBars (2)
	Combination of thek.bars and some stuff from rBars
]]
lolBars = CreateFrame("Frame");
lolBars:SetScript("OnEvent", function(self) self:OnEvent(event) end);
lolBars:RegisterEvent("VARIABLES_LOADED");

--local point, relativeTo, relativePoint, x, y, v, w, h, par, childframe, parentframe, anchor, x, y;
--local lolBars_frames = {};
local hooks = {};

local to_hide = { 
"MainMenuBarTexture0",
"MainMenuBarTexture1",
"MainMenuBarTexture2", 
"MainMenuBarTexture3", 
"BonusActionBarTexture0",
"BonusActionBarTexture1", 
"MainMenuXPBarTexture0", 
"MainMenuXPBarTexture1", 
"MainMenuXPBarTexture2", 
"MainMenuXPBarTexture3", 
"ReputationWatchBarTexture1", 
"ActionBarUpButton", 
"ActionBarDownButton", 
"MainMenuBarPageNumber", 
"MainMenuBarPerformanceBarFrame", 
"MainMenuMaxLevelBar0", 
"MainMenuMaxLevelBar1", 
"MainMenuMaxLevelBar2", 
"MainMenuMaxLevelBar3",
"MainMenuBarLeftEndCap", 
"MainMenuBarRightEndCap",

"CharacterMicroButton", 
"SpellbookMicroButton",
"TalentMicroButton", 
"QuestLogMicroButton", 
"SocialsMicroButton", 
"LFGMicroButton", 
"MainMenuMicroButton", 
"HelpMicroButton",

"MainMenuBarBackpackButton", 
"CharacterBag0Slot", 
"CharacterBag1Slot", 
"CharacterBag2Slot", 
"CharacterBag3Slot"
};

local to_hide_special = {
"ReputationWatchStatusBar", 
"SlidingActionBarTexture0",
"SlidingActionBarTexture1", 
"ShapeshiftBarLeft", 
"ShapeshiftBarMiddle",
"ShapeshiftBarRight", 
"SlidingActionBarTexture0", 
--"MainMenuExpBar",
--"ExhaustionTick", 
"SlidingActionBarTexture1"
}; 

KeyRingButton:Disable()
KeyRingButton:DisableDrawLayer()
KeyRingButton:Hide()

TalentMicroButton.Show = function() end;

ShapeshiftBarFrame:Hide()
ShapeshiftBarFrame.Show = function() end;

MainMenuExpBar:SetHeight(0.0000000000001) --me r haxx0r :O
MainMenuExpBar:Hide()
MainMenuExpBar.Show = function() end; 

ReputationWatchBar:SetHeight(0.00000000000001) --Hexxed u again, pwned
ReputationWatchBar:Hide()
ReputationWatchBar.Show = function() end;

ExhaustionTick:Hide()
ExhaustionTick.Show = function() end;

--ReputationWatchBarTexture1:SetHeight(0.000000000001)

MainMenuBarPerformanceBarFrame:Hide()
MainMenuBarPerformanceBarFrame.Show = function() end;
 
function lolBars:OnEvent(event)
	self:UnregisterEvent(event);
	self:InitAddon();
end

function lolBars:InitAddon()
        -- hiding some textures & frames
        for _, v in ipairs(to_hide) do
                getglobal(v):Hide();
            end
        for _, v in ipairs(to_hide_special) do
                getglobal(v):Hide();
                getglobal(v).Show = empty;
            end    
        self:Hooks();
end

--Placing Bars now =]
BonusActionButton1:SetPoint("BOTTOMLEFT",ActionButton1);


MainMenuBar:Show()
MainMenuBar:SetWidth(512)
MainMenuBar:SetFrameLevel(0)
MainMenuBar:SetFrameStrata("BACKGROUND")
MainMenuBar:SetPoint("Bottom",0,25)

MultiBarBottomLeftButton1:ClearAllPoints()  
MultiBarBottomLeftButton1:SetPoint("BOTTOMLEFT",MainMenuBar,"TOPLEFT",8,-6);

MultiBarBottomRightButton1:ClearAllPoints()  
MultiBarBottomRightButton1:SetPoint("BOTTOMLEFT",MultiBarBottomLeftButton1,"TOPLEFT",82,7);

PetActionButton1:ClearAllPoints()
PetActionButton1:SetPoint("BOTTOMLEFT",MultiBarBottomRightButton1,"TOPLEFT",7,15);

--Set my ConsumablesBar  	
local button;

for i = 1, 12, 1 do
    button = _G["MultiBarRightButton"..i];
    button:ClearAllPoints();
    if ( i > 1 ) then
		button:SetPoint("LEFT",_G["MultiBarRightButton"..(i-1)],"RIGHT",5,0);
	else
		button:SetPoint("BOTTOMRIGHT",UIParent,"BOTTOMRIGHT", -308, 48);
	end
end
  

-- Scaling the bars
MainMenuBar:SetScale(0.8)
--BonusActionBarFrame:SetScale(0.8)
MultiBarBottomLeft:SetScale(0.8)
MultiBarBottomRight:SetScale(0.6)
MultiBarRight:SetScale(0.5)
MultiBarLeft:SetScale(0.8)
PetActionBarFrame:SetScale(0.85)

 
        
    
-- ----------------------------------------------------------------------------
function lolBars:Hooks()
        -- this is where the magic happens
        -- BonusActionBar Hooks (hide textures if the actionbar swaps)
        hooks["onshow"] = BonusActionBarFrame:GetScript("OnShow");
        hooks["onshide"] = BonusActionBarFrame:GetScript("OnHide");
        
            BonusActionBarFrame:SetScript("OnShow", function(self,...)
                if ( hooks["onshow"] ) then hooks["onshow"](self,...); end;
                for i = 1, 12, 1 do
                        _G["ActionButton"..i]:SetAlpha(0);
                    end;
                end);
            BonusActionBarFrame:SetScript("OnHide", function(self,...)
                if ( hooks["onhide"] ) then hooks["onhide"](self,...); end;
                    for i = 1, 12, 1 do
                        _G["ActionButton"..i]:SetAlpha(1);
                        end;
                   end);
        -- Rangecheck
        hooks["ActionButton_OnUpdate"] = ActionButton_OnUpdate;
            
            ActionButton_OnUpdate = function(elapsed)
            if ( IsActionInRange(ActionButton_GetPagedID(this)) == 0) then
                    getglobal(this:GetName().."Icon"):SetVertexColor(0.3,0.3,0.3);
                    getglobal(this:GetName().."NormalTexture"):SetVertexColor(0.3,0.3,0.3);
                    range = 1;
            else
                    range = 0;
                end
            hooks["ActionButton_OnUpdate"](elapsed);
		
            if (this.range ~= range and range == 0) then
                    ActionButton_UpdateUsable()
                end
            this.range = range;
        end
    end
	

-- This gets ridof the ? on Healin/Buff spells when targeting self
ActionButton_OnUpdate = function(elapsed) 
  	local hotkey = getglobal(this:GetName().."HotKey");
  	local button = ActionButton_GetPagedID(this);
  
  	if ( hotkey:GetText() == RANGE_INDICATOR ) then
  			hotkey:Hide();
	end
end
-- Hide Hotkeys & Setup 4 making the buttonIcons look nicer
local mac = CreateFrame"Frame"
local Coo = CreateFrame"Frame"
mac:SetScript("OnEvent", function()
	for i = 1, 12, 1 do
		getglobal("ActionButton"..i.."HotKey"):Hide();
		getglobal("BonusActionButton"..i.."HotKey"):Hide();
		getglobal("MultiBarBottomLeftButton"..i.."HotKey"):Hide();
		getglobal("MultiBarBottomRightButton"..i.."HotKey"):Hide();
		getglobal("MultiBarLeftButton"..i.."HotKey"):Hide();
		getglobal("MultiBarRightButton"..i.."HotKey"):Hide();
	end
	local j
    for j=1,12 do
		Coo:ico("ActionButton", j)
		Coo:ico("BonusActionButton", j)
		Coo:ico("MultiBarBottomRightButton", j)
		Coo:ico("MultiBarBottomLeftButton", j)
		Coo:ico("MultiBarLeftButton", j)
		Coo:ico("MultiBarRightButton", j)
    end
end)
mac:RegisterEvent("PLAYER_LOGIN")
-- Now we gotta make the buttons look nicer
function Coo:ico(name, i)
	local bu  = _G[name..i]
	local ic  = _G[name..i.."Icon"]
	local nt  = _G[name..i.."NormalTexture"]
	
	nt:SetPoint("Center", 0, 0);
	
	ic:SetTexCoord(0.1,0.9,0.1,0.9)
    ic:SetPoint("TOPLEFT", bu, "TOPLEFT", 2, -2)
    ic:SetPoint("BOTTOMRIGHT", bu, "BOTTOMRIGHT", -2, 2)
end 

-- Hide MacroNames Here
for i = 1, 12, 1 do
	getglobal("ActionButton"..i.."Name"):Hide();
	getglobal("BonusActionButton"..i.."Name"):Hide();
	getglobal("MultiBarBottomLeftButton"..i.."Name"):Hide();
	getglobal("MultiBarBottomRightButton"..i.."Name"):Hide();
	getglobal("MultiBarLeftButton"..i.."Name"):Hide();
	getglobal("MultiBarRightButton"..i.."Name"):Hide();
end